import queryString from 'query-string';
export default {
  namespace: 'login',
  state: {
    todoList: ["Learn dva", "Learn road", "Learn liuxia"]
  },
  reducers: {
    'delete'(state, { payload: index }) {
      state.todoList = state.todoList.filter((item,i) => i !== index);
      return {...state};
    },
  },
  effects: {
    *beforeDelete (action, {call, put}) {
      yield call(() => {}, 10000);
      yield put({type: "delete", payload: action.payload})
    }
  },
  subscriptions: {
    setup({ dispatch, history }) {
      // 监听路由的变化，请求页面数据
      return history.listen(({ pathname, search }) => {
        // const query = queryString.parse(search);
        let list = [];
        if (pathname === 'todoList') {
          dispatch({ type: 'save', payload: {list} })
        }
      })
    }
  }
};
